<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>移动办公自动化系统</title>
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/base.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/info-mgt.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/WdatePicker.css" />

		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/jquery.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/common.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/WdatePicker.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/jquery.pagination.js"></script>
	</head>

	<body>
		<div class="title">
			<h2>
				等待审批
			</h2>
		</div>
		<form method="post"
			action="${pageContext.request.contextPath }/ComMethod.action?method=selectWaitApply">
			<div class="query">
				<div class="query-conditions ue-clear">
					<div class="conditions name ue-clear">
						<label>
							申请物品：
						</label>
						<p class="long-input ue-clear">
							<select id="selectcom" name="comname">
								<option>
									请选择
								</option>
								<c:forEach items="${requestScope.selectAll}" var="wait"
									varStatus="c">
									<option value="${wait.comName }">
										${wait.comName }
									</option>
								</c:forEach>
							</select>
						</p>
					</div>
					<div class="conditions name ue-clear">
						<label>
							申请人：
						</label>
						<p class="long-input ue-clear">
							<select id="selectuser" name="username">
								<option>
									请选择
								</option>
								<c:forEach items="${requestScope.selectAll}" var="wait"
									varStatus="c">
									<option value="${wait.userId }-${wait.username }">
										${wait.userId }-${wait.username }
									</option>
								</c:forEach>
							</select>
						</p>
					</div>
					<div class="conditions name ue-clear">
						<label>
							申请部门：
						</label>
						<p class="long-input ue-clear">
							<select id="selectdept" name="deptname">
								<option>
									请选择
								</option>
								<c:forEach items="${requestScope.selectAll}" var="wait"
									varStatus="c">
									<option value="${wait.userDept }">
										${wait.userDept }
									</option>
								</c:forEach>
							</select>
						</p>
					</div>
				</div>
				<div class="query-btn ue-clear">
					<input type="submit" id="submit" value="查询" />
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="reset" id="reset" value="重置">
				</div>
			</div>
			<div class="table-box">
				<table>
					<thead>
						<tr>
							<th class="num">
								序号
							</th>
							<th class="name">
								申请人id
							</th>
							<th class="process">
								申请人姓名
							</th>
							<th class="time">
								申请人部门
							</th>
							<th class="node">
								物品id
							</th>
							<th>
								物品类型
							</th>
							<th class="time">
								物品名称
							</th>
							<th class="time">
								申请数量
							</th>
							<th class="time">
								申请使用开始时间
							</th>
							<th class="time">
								申请使用结束时间
							</th>
							<th class="operate">
								操作
							</th>
						</tr>
					</thead>
					<c:forEach items="${requestScope.waitapply.data}" var="wait"
						varStatus="c">
						<tbody>
							<tr>
								<td class="num">
									${wait.applyId }
								</td>
								<td class="name">
									${wait.userId }                 
								</td>
								<td class="process">
									${wait.username }
								</td>
								<td class="node">
									${wait.userDept }
								</td>
								<td class="time">
									${wait.comId }
								</td>
								<td class="time">
									${wait.comType }
								</td>
								<td class="time">
									${wait.comName }
								</td>
								<td class="time">
									${wait.applyComnum }
								</td>
								<td class="time">
									${wait.startDate }
								</td>
								<td class="time">
									${wait.endDate }
								</td>
								<td class="operate">
									<label style="cursor: pointer; color: blue" onclick="passApply(${wait.applyId },${requestScope.waitapply.currentPage},${wait.comId },${wait.applyComnum })">
										通过
									</label>
									<label style="cursor: pointer; color: blue" onclick="unpassApply(${wait.applyId },${requestScope.waitapply.currentPage})">
										拒绝
									</label>
								</td>
							</tr>
						</tbody>
					</c:forEach>
				</table>
			</div>
			<div>
				<table width="80%" align="center" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<a onclick=skipPage('1');;>首页</a>
						</td>
						<td>
							<a
								onclick="skipPage('${requestScope.waitapply.currentPage==1?1:requestScope.waitapply.currentPage-1 }');">上一页</a>
						</td>
						<td>
							<a
								onclick="skipPage('${requestScope.waitapply.currentPage==requestScope.waitapply.totalPage?(requestScope.waitapply.currentPage):(requestScope.waitapply.currentPage+1) }');">下一页</a>
						</td>
						<td>
							<a onclick="skipPage('${requestScope.waitapply.totalPage}');">末页</a>
						</td>
						<td>
							当前页码：${requestScope.waitapply.currentPage}/${requestScope.waitapply.totalPage}
						</td>
					</tr>
				</table>
			</div>
		</form>
	</body>
	<script type="text/javascript">
	window.onload = removeselect();
	function removeselect() {
		$("#selectdept option").each(function() {
				var text = $(this).text();
				if ($("#selectdept option:contains('" + text + "')").length > 1)
				$("#selectdept option:contains('" + text + "'):gt(0)").remove();
			});
		$("#selectuser option").each(function() {
				var text = $(this).text();
				if ($("#selectuser option:contains('" + text + "')").length > 1)
				$("#selectuser option:contains('" + text+ "'):gt(0)").remove();
			});
		$("#selectcom option").each(function() {
			var text = $(this).text();
			if ($("#selectcom option:contains('" + text + "')").length > 1)
				$("#selectcom option:contains('" + text + "'):gt(0)").remove();
		});
		$("#selectcom option").each(function() {
			if($(this).val()=='${requestScope.select.comName}'){
				$(this).attr('selected',true);
			}
		});
		$("#selectdept option").each(function() {
			if($(this).val()=='${requestScope.select.deptName}'){
				$(this).attr('selected',true);
			}
		});
		$("#selectuser option").each(function() {
			if($(this).val()=='${requestScope.select.userName}'){
				$(this).attr('selected',true);
			}
		});
		if('${requestScope.passstatus}'=='0'){
			alert("申请数量大于所剩数量，暂时无法通过请求");
		}else if('${requestScope.passstatus}'=='1'){
			alert("操作成功");
		}else if('${requestScope.passstatus}'=='2'){
			alert("所申请物品已不存在，无法通过请求，请拒绝");
		}
	}
	function passApply(id, currentPage,comid,comnum) {
		var a = confirm("确认通过?");
		var url = '${pageContext.request.contextPath }/ComMethod.action?method=passApply&id=' + id;
		url += '&currPage=' + currentPage;
		url += '&username=' + document.getElementById("selectuser").value;
		url += '&status=' + 1;
		url += '&handler=' + '${login_User.userName }';
		
		url += '&deptname=' + document.getElementById("selectdept").value;
		url += '&comname=' + document.getElementById("selectcom").value;
		url += '&comid=' + comid;
		url += '&comnum=' + comnum;
		if (a) {
			window.location.href = url;
		} else {
			return false;
		}
	}
	function unpassApply(id, currentPage) {
		var a = confirm("确认拒绝?");
		var url = '${pageContext.request.contextPath }/ComMethod.action?method=passApply&id=' + id;
		url += '&currPage=' + currentPage;
		url += '&username=' + document.getElementById("selectuser").value;
		url += '&status=' + -1;
		url += '&handler=' + '${login_User.userName }';
		
		url += '&deptname=' + document.getElementById("selectdept").value;
		url += '&comname=' + document.getElementById("selectcom").value;
		if (a) {
			window.location.href = url;
		} else {
			return false;
		}
	}
	function skipPage(currentPage) {
		var url = '${pageContext.request.contextPath }/ComMethod.action?method=selectWaitApply&currPage=' + currentPage;
		url += '&username=' + document.getElementById("selectuser").value;
		url += '&deptname=' + document.getElementById("selectdept").value;
		url += '&comname=' + document.getElementById("selectcom").value;
		window.location.href = url;
	}
</script>
</html>
